package View.apply;

import Service.ServiceImpl.stustateServiceImpl;
import Service.ServiceImpl.systemMsgServiceImpl;
import Service.stustateService;
import Service.systemMsgService;
import View.Index.Index_user;
import domain.User;
import domain.systemMsg;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

public class IntoSchool extends JFrame {


    public IntoSchool(User user){
        init();
        componentInit(user);
    }

    public void init(){
        this.setTitle("返校签到");
        this.setSize(491,342);
        this.setResizable(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLayout(null);
    }
    public void componentInit(User user){
        //------------------JLabel--------------------
        JLabel label1= new JLabel();
        label1.setText("点击按钮签到");
        label1.setBounds(172,52,116,47);


        //------------------JButton--------------------
        JButton button1= new JButton();
        button1.setText("签到");
        button1.setBounds(180,148,97,44);

        JButton button2= new JButton();
        button2.setText("退出");
        button2.setBounds(180,188,97,44);



        this.add(label1);
        this.add(button1);
        this.add(button2);

        button1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                stustateService service = new stustateServiceImpl();
                service.sign(user.getUsername(),new Date(),"true");

                systemMsg msg = new systemMsg();
                msg.setUsername("管理员");
                msg.setTitle("学生签到");
                msg.setNeirong("学生"+user.getUsername()+"已签到");
                msg.setSendTime(new Date());
                msg.setIsread("false");
                systemMsgService service1 = new systemMsgServiceImpl();
                service1.addMsg(msg);


                JOptionPane.showMessageDialog(new JFrame(),"签到成功！");
            }
        });

        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                new Index_user(user).setVisible(true);
            }
        });
    }
}
